package com.wgts.wgts.control.dialog;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wgts.wgts.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/*
 *
 *
 *   data:2018/9/2115:24
 *
 */public class ShopDeleteDialogFragment extends AbstractCustomDialogFragment {
    @BindView(R.id.delete_text)
    TextView deleteText;
    @BindView(R.id.delete_ly)
    LinearLayout deleteLy;
    Unbinder unbinder;
    private static final String Sbundle = "ToastMessage";
    private String showText;
    private OnClickListener onClickListener;

    @Override
    public void onStart() {
        super.onStart();
        // 设置宽度为屏宽, 靠近屏幕底部。
        Window win = getDialog().getWindow();
        // 一定要设置Background，如果不设置，window属性设置无效
        win.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

        DisplayMetrics dm = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);

        WindowManager.LayoutParams params = win.getAttributes();
        params.gravity = Gravity.CENTER;
        // 使用ViewGroup.LayoutParams，以便Dialog 宽度充满整个屏幕
        params.width = ViewGroup.LayoutParams.MATCH_PARENT;
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        win.setAttributes(params);
    }

    @Override
    public View onCreateDialogView() {
        Bundle bundle = getArguments();
        if (bundle != null){
            showText = bundle.getString(Sbundle);
        }
        View view = LayoutInflater.from(getContext()).inflate(R.layout.shop_delete_dialog_fragment, null);
        unbinder = ButterKnife.bind(this,view);
        deleteText.setText(showText);
        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick(R.id.delete_ly)
    public void onViewClicked() {
        if (onClickListener != null){
            onClickListener.delete();
        }
    }

    public static ShopDeleteDialogFragment getShopDeleteDialogFragment(String showText) {
        ShopDeleteDialogFragment fragment = new ShopDeleteDialogFragment();
        Bundle bundle = new Bundle();
        bundle.putString(Sbundle, showText);
        fragment.setArguments(bundle);
        return fragment;
    }
    public interface OnClickListener{
        void delete();
    }

    public void setOnClickListener(OnClickListener onClickListener){
        this.onClickListener = onClickListener;
    }
}
